//
//  RootViewController.m
//  UI18_数据库第三方_练习
//
//  Created by dllo on 15/12/2.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"
#import "Student.h"
#import "DataBaseHandle.h"
@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor colorWithRed:0.870 green:1.000 blue:0.925 alpha:1.000];
    
}
- (IBAction)openDB:(id)sender {
    [[DataBaseHandle shareDataBase] openDB];
    
}
- (IBAction)closeDB:(id)sender {
    [[DataBaseHandle shareDataBase] closeDB];
    
}
- (IBAction)createDB:(id)sender {
    [[DataBaseHandle shareDataBase] createTable];
    
}
- (IBAction)deleteDB:(id)sender {
    [[DataBaseHandle shareDataBase] deleteTable];
}
- (IBAction)insortTable:(id)sender {
    Student *stu = [[Student alloc] init];
    stu.name = @"王宁";
    stu.sex = @"女";
    stu.age = 18;
    [[DataBaseHandle shareDataBase] insertDataWithStudent:stu];
}

- (IBAction)updateTable:(id)sender {
    Student *stu = [[Student alloc] init];
    stu.name = @"宋玉";
    stu.sex = @"男";
    stu.age = 28;
    [[DataBaseHandle shareDataBase] updateData:stu num:2];
    
    
}
- (IBAction)deleteTable:(id)sender {
    [[DataBaseHandle shareDataBase] deleteDataWithNumber:2];
}
- (IBAction)searchData:(id)sender {
    
    NSMutableArray *arr = [[DataBaseHandle shareDataBase] searchDB];
    for (Student *stu in arr) {
        NSLog(@"%@ %@ %ld", stu.name, stu.sex, stu.age);
    }
    
    
}
- (IBAction)searchDataByGroup:(id)sender {
    
    NSMutableArray *arr = [[DataBaseHandle shareDataBase] searchBySex:@"男"];
    for (Student *stu in arr) {
        NSLog(@"%@ %@ %ld", stu.name, stu.sex, stu.age);
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
